home *** CD-ROM | disk | FTP | other *** search
- // Modified: 12 Dec 1990 - John Grothman
- // Now works with 4DOS, as well as PC-DOS and MS-DOS.
- // (look around line 213 for the change)
-
- main()
- {
- int count, hi_hour, lo_hour, hi_min, lo_min, hi_sec, lo_sec, local_hr, t;
- int error, err_test, y1, y2, y3, y4, y5, day, month, year;
- int julian1, julian2, julian3, julian4, julian5, julian6, julian7, julian8;
- str utc_hour[3], slocal_hr[3];
- str set_dos_time[20]="time ", set_dos_date[20]="date ";
- str juldatestr[10] = " ";
- str geordatestr[10] = " ";
- str monthstr[3], daystr[3], yearstr[4];
- int integerdate;
-
- // Initialize variables
- error = 1; //Indicates that time info is yet to be decoded properly
- err_test = -1; //Used to detect if time info is properly received
- hi_hour = -1; //Receives hi byte of hour time info
- lo_hour = -1; //Receives lo byte of hour time info
- hi_min = -1; //Receives hi byte of minute time info
- lo_min = -1; //Receives lo byte of minute time info
- hi_sec = -1; //Receives hi byte of second time info
- lo_sec = -1; //Receives lo byte of second time info
- julian1 = -1;
- julian2 = -1;
- julian3 = -1;
- julian4 = -1;
- julian5 = -1;
- _alarm_on = 0;
- _sound_on = 0;
-
- //Show opening TIMESET display
- clear_scr();
- prints("");
- prints("Welcome to Timeset!!!");
- prints("Now dialing The Naval Observertory for the time...");
-
- //Dial for the time
- set_cparams(1200,0,8,1);
- if (!dial("m9-1-202-653-0351",10))
- {
- prints("Can not contact the Naval Observatory! Giving up!");
- tone(300,1);
- return; //After 10 tries can't reach the time. Abort.
- }
-
- // Decode the modified Julian time info received
- while (error)
- {
-
- if (!waitfor("UTC",10))
- {
- prints("Timeout error, aborting!");
- hangup();
- _alarm_on = 0;
- _sound_on = 0;
- return; //Time info is not flowing right. Abort.
- }
-
- if (!waitfor("*",3))
- {
- prints("Timeout error, aborting!");
- hangup();
- _alarm_on = 0;
- _sound_on = 0;
- return; //Time info is not flowing right. Abort.
- }
- flushbuf();
-
- count = 2; //Amount of bytes to wait until date data should start
- while (count)
- {
- while (cgetc() == -1)
- {
- }
- count = count - 1;
- }
- while (julian1 == -1)
- {
- julian1 = cgetc();
- }
- while (julian2 == -1)
- {
- julian2 = cgetc();
- }
- while (julian3 == -1)
- {
- julian3=cgetc();
- }
- while (julian4 == -1)
- {
- julian4 = cgetc();
- }
- while (julian5 == -1)
- {
- julian5 = cgetc();
- }
-
- count = 5; //Amount of bytes to wait until time data should start
- while (count)
- {
- while (cgetc() == -1)
- {
- }
- count = count - 1;
- }
-
- //Receive the time data
- while (hi_hour == -1)
- {
- hi_hour = cgetc();
- }
- while (lo_hour == -1)
- {
- lo_hour = cgetc();
- }
- while (hi_min == -1)
- {
- hi_min = cgetc();
- }
- while (lo_min == -1)
- {
- lo_min = cgetc();
- }
- while (hi_sec == -1)
- {
- hi_sec = cgetc();
- }
- while (lo_sec == -1)
- {
- lo_sec = cgetc();
- }
- if (waitfor("UTC",2))
- {
- error = 0;
- }
- }
-
- //Start building the DOS set time command
- strcat(utc_hour, hi_hour);
- strcat(utc_hour, lo_hour);
- local_hr = stoi(utc_hour);
-
- // ****************** Adjust UTC time to local time here *****************
- //Pacific Daylight time is -7 hours
- //Pacific Standard time is -8 hours
- //Central Standard time is -6 hours
-
- local_hr = local_hr - 6;
-
- // ***********************************************************************
- // ***********************************************************************
-
- if (local_hr < 0)
- {
- local_hr = local_hr + 24;
- }
- itos(local_hr, slocal_hr);
-
- //Set DOS time
- strcat(set_dos_time, slocal_hr);
- strcat(set_dos_time, ":");
- strcat(set_dos_time, hi_min);
- strcat(set_dos_time, lo_min);
- strcat(set_dos_time, ":");
- strcat(set_dos_time, hi_sec);
- strcat(set_dos_time, lo_sec);
- dos(set_dos_time, 0);
-
- clear_scr();
- prints("");
- prints("");
- prints("");
- prints("");
- prints("");
- prints("");
- gotoxy(28, gety());
- prints("SUCCESSFULLY set time");
- //Hangup the modem and clear extra received data
- hangup();
- flushbuf();
-
- //Set DOS date
- strcat(juldatestr, "24"); // Add epoch
- strcat(juldatestr, julian1);
- strcat(juldatestr, julian2);
- strcat(juldatestr, julian3);
- strcat(juldatestr, julian4);
- strcat(juldatestr, julian5);
-
- // ** julian to calender date algorithm **
-
- // The algorithm was obtained directly from the Naval Observatory
- // and should be valid for the next 140 years.
- // If you use it elsewhere, be careful of the integer roundoff.
- // The precedences are critical, therefore the () are inserted
- // to clarify them and prevent mistranslation by the reader.
-
- integerdate = stoi(juldatestr);
- y1 = integerdate + 68569;
- y2 = (4 * y1) / 146097;
- y3 = y1 - (((146097 * y2) + 3) / 4);
- year = (4000 * (y3 + 1)) / 1461001;
- y4 = (y3 - ((1461 * year) / 4)) + 31;
- month = (80 * y4) / 2447;
- day = y4 - ((2447 * month) / 80);
- day = day + 1;
- y5 = month / 11;
- month = month + 2 - (12 * y5);
- // year = 100 * (y2 - 49) + year + y5;
- year = (100 * (y2 - 49) + year + y5) - 1900;
-
-
- itos(integerdate, geordatestr);
- itos(month, monthstr);
- itos(day, daystr);
- itos(year, yearstr);
-
- //Set DOS date
- strcat(set_dos_date, monthstr);
- strcat(set_dos_date, "-");
- strcat(set_dos_date, daystr);
- strcat(set_dos_date, "-");
- strcat(set_dos_date, yearstr);
- dos(set_dos_date, 0);
-
-
- //Display current time continuosly
- _scr_chk_key = 0; //Disable keyboard scan so inkey will work properly
- cursor_onoff(0); //Disable the cursor because it is annoying
- clear_scr();
- prints("");
- prints("");
- prints("");
- printsc("julian date = ");
- prints(juldatestr);
- prints("");
- prints("");
- printsc("month = ");
- prints(monthstr);
- printsc("day = ");
- prints(daystr);
- printsc("year = ");
- prints(yearstr);
- prints("");
- prints("");
- prints("");
- prints("Press esc to exit");
- prints("");
- printsc("The time received from the Naval Observatory is , adjusted to local time.");
-
- while (1)
- {
- gotoxy(48, gety());
- t = curtime();
- if (thour(t) < 10)
- {
- printsc("0");
- }
- printn(thour(t));
- if (tmin(t) < 10)
- {
- printsc("0");
- }
- printn(tmin(t));
- printsc(".");
- if (tsec(t) < 10)
- {
- printsc("0");
- }
- printn(tsec(t));
- if (inkey() == 27)
- {
- break; //Exit if the esc key is pressed
- }
- }
-
- clear_scr();
- prints("Thank you for using TIMESET!");
- exittelix(0, 1);
- }
-